import java.util.ArrayList;
import java.util.Comparator;

/**
 * @description:
 * @Author: wuzhenbin
 * @CreateTime: 2025-02-15
 */
public class leetcode_148 {
    public static void main(String[] args) {

    }

    public ListNode sortList(ListNode head) {
        if(head==null)return null;
        ListNode cur = head;
        ArrayList<Integer> list = new ArrayList<>();
        while(cur!=null){
            list.add(cur.val);
            cur = cur.next;
        }
        list.sort(Integer::compareTo);
        cur = head;
        for (Integer i : list) {
            cur.val =i;
            cur = cur.next;
        }
        return head;
    }

    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

}
